package com.yxhl.km.module.track;

import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.yxhl.km.R;
import com.yxhl.km.base.BaseFragment;
import com.zhy.autolayout.AutoFrameLayout;
import com.zhy.autolayout.AutoLinearLayout;
import com.zhy.autolayout.AutoRelativeLayout;

import butterknife.BindView;

/**
 * Created by 张亚楠 on 2018/5/28.
 */

public class TrackFragment extends BaseFragment {
    @BindView(R.id.iv_lieft)
    ImageView ivLieft;
    @BindView(R.id.tv_left)
    TextView tvLeft;
    @BindView(R.id.rl_left)
    AutoRelativeLayout rlLeft;
    @BindView(R.id.tv_right)
    TextView tvRight;
    @BindView(R.id.rl_right)
    AutoRelativeLayout rlRight;
    @BindView(R.id.iv_right)
    ImageView ivRight;
    @BindView(R.id.fl)
    AutoFrameLayout fl;
    @BindView(R.id.activity_main)
    AutoLinearLayout activityMain;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_track;
    }

    @Override
    protected void initListener() {
        rlRight.setOnClickListener(this);
        rlLeft.setOnClickListener(this);

    }

    @Override
    protected void initialized() {
        initData();
    }

    private void initData() {
        tvLeft.setText("车辆跟踪");
        tvRight.setText("运输跟踪");
        changeView(0);
        CarTrackFragment carTrackFragment = new CarTrackFragment();//消息
        FragmentManager fm = getActivity().getSupportFragmentManager();
        FragmentTransaction transaction = fm.beginTransaction();
        transaction.replace(R.id.fl, carTrackFragment);
        transaction.commit();
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.rl_left:
                changeView(0);
                FragmentManager fm = getActivity().getSupportFragmentManager();
                FragmentTransaction transaction = fm.beginTransaction();
                CarTrackFragment leaveFragment = new CarTrackFragment();//消息
                transaction.replace(R.id.fl, leaveFragment);
                transaction.commit();
                break;
            case R.id.rl_right:
                changeView(1);
                FragmentManager fm1 = getActivity().getSupportFragmentManager();
                FragmentTransaction transaction1 = fm1.beginTransaction();
                TransportTrackFragment instationFragment = new TransportTrackFragment();//群组
                transaction1.replace(R.id.fl, instationFragment);
                transaction1.commit();
                break;
        }


    }

    //手动设置ViewPager要显示的视图
    private void changeView(int desTab) {
        switch (desTab) {
            //左边显示
            case 0:
                rlLeft.setBackgroundResource(R.drawable.shape_btn_weith);
                rlRight.setBackgroundResource(0);
                tvRight.setTextColor(getResources().getColor(R.color.white));
                tvRight.setBackgroundColor(0);
                tvLeft.setTextColor(getResources().getColor(R.color.main_color));
                tvLeft.setBackgroundColor(getResources().getColor(R.color.white));
                ivLieft.setVisibility(View.GONE);
                ivRight.setVisibility(View.GONE);
                break;
            //右边显示
            case 1:
                tvRight.setTextColor(getResources().getColor(R.color.main_color));
                tvRight.setBackgroundColor(getResources().getColor(R.color.white));
                rlRight.setBackgroundResource(R.drawable.shape_btn_weith);
                rlLeft.setBackgroundResource(0);
                tvLeft.setTextColor(getResources().getColor(R.color.white));
                tvLeft.setBackgroundColor(0);
                ivLieft.setVisibility(View.GONE);
                ivRight.setVisibility(View.VISIBLE);
                break;
        }


    }

}
